package com.hzsai.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author: hzsai
 * @date : 2020/3/17
 * usage:
 **/
public class MyAsyncUncaughtExceptionHandler implements AsyncUncaughtExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(MyAsyncUncaughtExceptionHandler.class);

    /**
     * 处理没有捕获的异常
     *
     * @param throwable
     * @param method
     * @param objects
     */
    @Override
    public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
        logger.debug(
                "Throwable message:{} -- methods:{} -- objects:{}",
                throwable.getMessage(),
                method.getName(),
                Arrays.stream(objects).sorted().map(object -> "Param: " + object).toArray()
        );
    }
}
